package com.zsh.weather.ln.home.ui.home.model
import com.zsh.weather.ln.base.OnLoadDataListener
import com.zsh.weather.ln.bean.IndicesBase
import com.zsh.weather.ln.bean.NowBase
import com.zsh.weather.ln.https.BaseCallBack
import com.zsh.weather.ln.https.RequestManager
import com.zsh.weather.ln.utils.Constant
import okhttp3.Call

class HomeModel{
    fun getNowWeather(location: String, onLoadDataListener: OnLoadDataListener) {
        var params: HashMap<String, String> = hashMapOf()
        params.put("location", location)
        params.put("key", Constant.key)
        RequestManager().doGet(Constant.url_now, null, params)
            .execute(object : BaseCallBack<NowBase>(NowBase::class.java) {
                override fun success(call: Call?, data: NowBase) {
                    onLoadDataListener.success(data)
                }

                override fun fail(error: String) {
                    onLoadDataListener.fail(error)
                }
            })
    }
    fun getIndices(location: String, onLoadDataListener: OnLoadDataListener) {
        var params: HashMap<String, String> = hashMapOf()
        params.put("location", location)
        params.put("key", Constant.key)
        params.put("type","0")
        RequestManager().doGet(Constant.url_indices, null, params)
            .execute(object : BaseCallBack<IndicesBase>(IndicesBase::class.java) {
                override fun success(call: Call?, data: IndicesBase) {
                    onLoadDataListener.success(data)
                }

                override fun fail(error: String) {
                    onLoadDataListener.fail(error)
                }
            })
    }
}